﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ClassLibrary;

namespace ObTookit
{
    /// <summary>
    /// 自动类的初始化
    /// 
    /// Reload按钮，使修改后的配置生效
    /// </summary>
    public class AutoInitiator
    {
        public void SetEffetive()
        {

        }
        public AutoObject SetAutoObject(string dbName, string tbName, string tbDescri)
        {
            AutoObject auto = new AutoObject();
            try
            {
                auto.OmNS = ConfigurationManager.AppSettings["ModelNS"];
                auto.QryNS = ConfigurationManager.AppSettings["QueryNS"];
                auto.PermitNS = ConfigurationManager.AppSettings["PermitNS"];
                auto.DaNS = ConfigurationManager.AppSettings["DalNS"];
                auto.LgNS = ConfigurationManager.AppSettings["LgNS"];
                auto.ServNS = ConfigurationManager.AppSettings["ServerNS"];
                auto.ApiNS = ConfigurationManager.AppSettings["ApiNS"];
                auto.CtrlNS = ConfigurationManager.AppSettings["CtrlNS"];
                auto.ViewNS = ConfigurationManager.AppSettings["ViewNS"];
                //
                auto.LgBaseCls = ConfigurationManager.AppSettings["LgBaseCLS"];
                auto.ServBaseCls = ConfigurationManager.AppSettings["ServBaseCLS"];
                auto.ApiBaseCls = ConfigurationManager.AppSettings["ApiBaseCLS"];
                //auto.CtrlBaseCls = ConfigurationManager.AppSettings["CtrlBaseCls"];

                auto.BaseNS = ConfigurationManager.AppSettings["BaseNS"];
                auto.BaseSession = ConfigurationManager.AppSettings["BaseSession"];

                auto.ApiPrefix = ConfigurationManager.AppSettings["ApiPrefix"];

                auto.DbName = dbName;
                auto.DbAlias = ConfigurationManager.AppSettings["DbAlias"];
                auto.TbName = tbName;

                auto.TbDescri = tbDescri.TrimEnd("表".ToCharArray());
                auto.ClsName = StringUtil.FirstChar(tbName, "_", true).TrimEnd('s');// StringUtil.FirstUpper(tbName, '_').TrimEnd('s');
            }
            catch (Exception)
            {
                //MessageBox.Show("读取AutoObject相关配置异常！", "警告"
                //    , MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
                throw;                
            }
            return auto;
        }
    }
}
